const app = getApp();
Page({
  data: {
    circles: [],
  },
  onLoad: function (options) {
    var self = this;
    wx.getStorage({
      key: 'latitude',
      success: res => {
        self.setData({
          latitude: res.data
        })
      }
    })
    wx.getStorage({
      key: 'longitude',
      success: res => {
        self.setData({
          longitude: res.data
        })
      }
    })
    wx.getStorage({
      key: 'key',
      success: res => {
        self.setData({
          key: res.data
        })
        self.getArea()
      }
    })
  },
  getArea: function () {
    let self = this;
    wx.request({
      url: app.globalData.ApiUrl + '/index.php?act=member_address&op=get_area',
      data: {
        key: self.data.key,
      },
      method: 'POST',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      dataType: 'json',
      success: (res) => {
        if (res.data.code == 200) {
          let areaInfo = res.data.datas;
          let circles = [];
          for (let i = 0; i < areaInfo.length; i++) {
            circles[i] = {
              latitude: areaInfo[i].logistics_reference_lat,
              longitude: areaInfo[i].logistics_reference_lng,
              color: '#7cb5ec88',
              fillColor: '#7cb5ec88',
              radius: areaInfo[i].logistics_distance * 1000,
              strokeWidth: 1
            }
          }
          self.setData({
            circles
          })
        }
      }
    });
  },
  onReady: function () {
    this.mapCtx = wx.createMapContext('myMap');
  },
})